      SUBROUTINE GIMBL1(SY1,SY2,SY3,CIY)
C
      IMPLICIT REAL*8(A-H,O-Z)
C
      COMMON/CGIMBL/ AZIN(3,3),AZAX(3),AZCG(3),AZMS,AZYY(3,3),AZIAX(3,3)
     1              ,ELIN(3,3),ELAX(3),ELCG(3),ELMS,ELYY(3,3),ELIAX(3,3)
     2              ,ZZAZ(3,3)
C
      COMMON/CONSTS/ PI,TWOPI,RADIAN
C
      COMMON/GMBLWK/ DELT(2,2),GAMGM(2,6),GMRHS(2),DI(2,2),DIGAM(2,6)
     1              ,DZML(6,6),YAZB(3),YELC(3)
C
      COMMON/GMBOUT/ AZ,AZD,EL,ELD,B(3,3),B0(3,3),B0B(3,3),C(3,3)
     1              ,B0BC(3,3),ZEL(3),YEL(3),YAZ(3),ZAZM(3),ZELM(3)
C
      COMMON/GMPRPL/ GMBAZ,GMBAZD,GMBEL,GMBELD
C
      COMMON/GMRSOT/ AZDD,ELDD,RSRHST(3),RSRHSR(3)
C
      COMMON/IGIMBL/ IGMBL,NAZIM,NELEV,NA1,NE1
C
      COMMON/IRSTGM/ IGMRST,IARST(3),IRSCY(3)
C
      COMMON/RPOOL1/ DUMV1(80),YBCM(3),DUMV2(42)
C
      COMMON/VARBLS/ DEP(150),DER(150)
C
C
C
      DIMENSION CIY(3,3),DM1(3,3),DM2(3,3),DM3(3,3),DM4(3,3),DM5(3,3)
      DIMENSION DM0(3,3),DM6(3,3),DM7(3,3),DM8(3,3),DM9(3,3)
      DIMENSION V1(3),V2(3),V3(3),V4(3),V5(3),V6(3),V7(3),V8(3),V9(3)
      DIMENSION ANGM(3),ANGMD(3),ANGMDD(3)
C
      IF(IGMBL.EQ.0) RETURN
C
C     GIMBL1 IS CALLED FROM FNDALP TO INCLUDE GIMBLE MASS PROPERTIES
C     IN SYSTEM INERTIA PROPERTIES
C
C     GIMBLE RASTERING OPTION
C
      IF(IGMRST.EQ.0) GO TO 110
C
      DO 103 I=1,3
      ANGM(I)=0.0D0
      ANGMD(I)=0.0D0
      ANGMDD(I)=0.0D0
  103 CONTINUE
C
      CALL RASTGM(ANGM,ANGMD,ANGMDD)
C
      AZ=ANGM(1)
      AZD=ANGMD(1)
      AZDD=ANGMDD(1)
C
      EL=ANGM(3)
      ELD=ANGMD(3)
      ELDD=ANGMDD(3)
C
      GO TO 120
C
  110 CONTINUE
C
C
      AZ=DEP(NAZIM)
      AZD=DEP(NA1)
      EL=DEP(NELEV)
      ELD=DEP(NE1)
C
  120 CONTINUE
C
      GMBAZ=AZ/RADIAN
      GMBAZD=AZD/RADIAN
      GMBEL=EL/RADIAN
      GMBELD=ELD/RADIAN
C
      SAZ=DSIN(AZ)
      CAZ=DCOS(AZ)
      SEL=DSIN(EL)
      CEL=DCOS(EL)
C
      C(1,1)=CEL
      C(3,3)=CEL
      C(1,3)=SEL
      C(3,1)=-SEL
      B(1,1)=CAZ
      B(2,2)=CAZ
      B(1,2)=-SAZ
      B(2,1)=SAZ
C
      CALL MPYMAT(B0,B,DM1,1,1,B0B,DM1)
      CALL MPYMAT(B0B,C,DM1,1,1,B0BC,DM1)
C
      CALL MATV(1,C,ELCG,V5)
      CALL ADDV(V5,ELAX,ZEL)
      CALL MATV(1,B0B,ZEL,V6)
      CALL MATV(2,C,ZEL,V9)
      CALL ADDV(AZAX,V6,YEL)
      CALL MATV(2,B0B,AZAX,V7)
      CALL MATV(1,B0B,AZCG,V1)
      CALL ADDV(AZAX,V1,YAZ)
C
      CALL MPYMAT(C,ELYY,C,2,2,DM2,DM1)
      CALL MPYMAT(B0BC,ELYY,B0BC,2,2,DM3,DM2)
      CALL MPYMAT(B0B,AZYY,B0B,2,2,DM4,DM3)
C
      DO 5 I=1,3
      DO 4 J=1,3
      ZZAZ(I,J)=AZIAX(I,J)+DM1(I,J)+ELMS*ZEL(I)*ZEL(J)
      DM5(I,J)=DM1(I,J)+AZYY(I,J)+ELMS*ZEL(I)*V7(J)+AZMS*AZCG(I)*V7(J)
      DM6(I,J)=ELIAX(I,J)+ELMS*ELCG(I)*V9(J)
      CIY(I,J)=CIY(I,J)+DM2(I,J)+DM3(I,J)+ELMS*YEL(I)*YEL(J)
     1         +AZMS*YAZ(I)*YAZ(J)
    4 CONTINUE
      V3(I)=ELMS*YEL(I)+AZMS*YAZ(I)
      YBCM(I)=YBCM(I)+V3(I)
      ZAZM(I)=ELMS*ZEL(I)+AZMS*AZCG(I)
      ZELM(I)=ELMS*ELCG(I)
    5 CONTINUE
C
      SY1=SY1+V3(1)
      SY2=SY2+V3(2)
      SY3=SY3+V3(3)
C
      DELT(1,1)=ZZAZ(1,1)+ZZAZ(2,2)
      DELT(2,2)=ELIAX(3,3)+ELIAX(1,1)
      CALL MATV(2,C,ELAX,V1)
      DELT(2,1)=-C(3,3)*(ELYY(3,2)+ELMS*ELCG(3)*(ELCG(2)+V1(2)))
     1          -C(3,1)*(ELYY(1,2)+ELMS*ELCG(1)*(ELCG(2)+V1(2)))
      DELT(1,2)=DELT(2,1)
C
      CALL MATV(2,B0B,AZAX,YAZB)
      CALL ADDV(YAZB,ELAX,V2)
      CALL MATV(2,C,V2,YELC)
      V4(1)=-(ELIAX(1,2)+ZELM(1)*YELC(2))
      V4(2)=ELIAX(3,3)+ZELM(3)*YELC(3)+ELIAX(1,1)+ZELM(1)*YELC(1)
      V4(3)=-(ELIAX(3,2)+ZELM(3)*YELC(2))
      CALL MATV(1,B0BC,V4,V2)
      V4(1)=-(ZZAZ(1,3)+ZAZM(1)*YAZB(3))
      V4(2)=-(ZZAZ(2,3)+ZAZM(2)*YAZB(3))
      V4(3)=ZZAZ(1,1)+ZAZM(1)*YAZB(1)+ZZAZ(2,2)+ZAZM(2)*YAZB(2)
      CALL MATV(1,B0B,V4,V1)
C
      DO 10 I=1,3
      GAMGM(1,I)=B0B(I,2)*ZAZM(1)-B0B(I,1)*ZAZM(2)
      GAMGM(2,I)=B0BC(I,1)*ZELM(3)-B0BC(I,3)*ZELM(1)
      I3=I+3
      GAMGM(1,I3)=V1(I)
      GAMGM(2,I3)=V2(I)
   10 CONTINUE
C
C
      DEN=DELT(1,1)*DELT(2,2)-DELT(1,2)*DELT(2,1)
      DI(1,1)=DELT(2,2)/DEN
      DI(2,2)=DELT(1,1)/DEN
      DI(1,2)=-DELT(1,2)/DEN
      DI(2,1)=-DELT(2,1)/DEN
C
      DO 15 I=1,2
      DO 15 J=1,6
      DIGAM(I,J)=DI(I,1)*GAMGM(1,J)+DI(I,2)*GAMGM(2,J)
   15 CONTINUE
C
      DO 20 I=1,6
      DO 20 J=1,6
      DZML(I,J)=GAMGM(1,I)*DIGAM(1,J)+GAMGM(2,I)*DIGAM(2,J)
   20 CONTINUE
C
C
      IF(IGMRST.EQ.0) RETURN
C
      V8(1)=-DM5(1,3)*AZDD
      V8(2)=-DM5(2,3)*AZDD
      V8(3)=(DM5(1,1)+DM5(2,2))*AZDD
C
      CALL MATV(1,B0B,V8,V1)
C
      V8(1)=-DM6(1,2)*ELDD
      V8(2)=(DM6(3,3)+DM6(1,1))*ELDD
      V8(3)=-DM6(3,2)*ELDD
C
      CALL MATV(1,B0BC,V8,V2)
C
      V8(1)=-ZAZM(2)*AZDD
      V8(2)= ZAZM(1)*AZDD
      V8(3)=0.0D0
C
      CALL MATV(1,B0B,V8,V3)
C
      V8(1)= ZELM(3)*ELDD
      V8(2)= 0.0D0
      V8(3)=-ZELM(1)*ELDD
C
      CALL MATV(1,B0BC,V8,V4)
C
      DO 140 I=1,3
      RSRHST(I)=-V3(I)-V4(I)
      RSRHSR(I)=-V1(I)-V2(I)
  140 CONTINUE
C
C
      RETURN
C
      END
